﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ASPItalia.ModelVirtualCasting.Web;
using System.Windows.Navigation;
using ASPItalia.ModelVirtualCasting.Web.RiaServices;
using ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.ViewModels;
using ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.Views;

namespace ASPItalia.ModelVirtualCasting.Silverlight.BackOffice
{
    public partial class MainPage : ViewPageBase
    {
        public MainPage()
        {
            InitializeComponent();
            Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
            Application.Current.CheckAndDownloadUpdateAsync();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
        {
            if (e.UpdateAvailable)
            {
                MessageBox.Show("Il programma è stato aggiornato, chiudere e riaprire l'applicazione");
            }
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Frame = ContentFrame;
        }

        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {
        }

        private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            ErrorWindow.CreateNew(e.Exception);
        }

        private new MainPageViewModel ViewModel
        {
            get
            {
                return (MainPageViewModel)base.ViewModel;
            }
        }

        private void ViewPageBase_Drop(object sender, DragEventArgs e)
        {
        }
    }
}
